class GrowlApp

  FILE_DIR = File.expand_path(File.dirname(__FILE__))

  NOTIFY_SCPT = FILE_DIR + '/notify.scpt'
  REGISTER_SCPT = FILE_DIR + '/register.scpt'

  def initialize
    register
  end

  def display(title, content='', icon=nil)
    if icon.nil?
      if title =~ /(succeeded|failed|loaded error)/i
        icon = "#{FILE_DIR}/#{$1}.png"
      else
        icon = "#{FILE_DIR}/succeeded.png"
      end
    end
    system %{/usr/bin/osascript #{NOTIFY_SCPT} "#{title}" "#{content}" "#{icon}"}
  end

  def register
    system %{/usr/bin/osascript #{REGISTER_SCPT}}
  end
end